// import AdvancedSearch from "@/gcfx_web/components/AdvancedSearch";
// import useAdvancedSearch from "@/gcfx_web/components/AdvancedSearch/useAdvancedSearch";
import SelectSearch, { ISearchParams } from "@/gcfx_web/components/SelectSearch";
import { IUseProComparePage } from "@/gcfx_web/defaultConfig/config";
import { Button, Select } from "antd";
import Search from "antd/es/input/Search";
import { IColumnsType } from "hy_dev_lib";
import { useState } from "react";


const useProComparePage: IUseProComparePage = (props) => {
  //TODO: AdvancedSearch, useAdvancedSearch 作为参数传入 不能直接 import  否则相互引用  会报错！！！！
  const { proFileInfo, pageType, AdvancedSearch, useAdvancedSearch } = props

  const [proFilterValue, setProFilterValue] = useState({})

  const getCompareProTableCols = (defaultCols: IColumnsType) => {
    return defaultCols
  }

  return {
    // getShowCompareProName: (proInfo: any) => proInfo.gcmc, //对比工程表头显示的工程名称 默认显示 gcmc
    // proFileterEle: <ProFileter pageType={pageType} proFilterValue={proFilterValue} setProFilterValue={setProFilterValue}></ProFileter>, // 选择对比工程弹窗 筛选组件
    // proFilterValue,  // 选中对比工程弹窗 筛选条件的值(一个对象)
    // getCompareProTableCols: getCompareProTableCols
  }
}

export default useProComparePage


const ProFileter = (props: any) => {
  const { pageType, AdvancedSearch, useAdvancedSearch } = props
  const [optionSelect, setOptionSelect] = useState<Number[]>([]);//文件类型下拉框选中的值
  const [inputVal, setInputVal] = useState("");
  const [searchVal, setSearchVal] = useState([]);
  //头部搜索数据
  const [searchParams, setSearchParams] = useState<ISearchParams>({
    searchType: 0,//下拉选项
    keywords: ""//输入的文字
  });
  const { keywords, searchType } = searchParams;

  //文件类型下拉框选择的回调
  const handleChange = (value: any) => {
    if (!value) {
      if (pageType) {
        setOptionSelect([70, 52, 50]);
      } else {
        setOptionSelect([70, 52, 50, 68, 66, 41, 21]);
      }
    } else {
      let arr = [];
      arr.push(value);
      setOptionSelect(arr);
    }
  };

  const onSearch = (advancedSearchVal?: any) => {
    const newSearchVal: any = advancedSearchVal || advancedSearch;
    setSearchVal(newSearchVal);
  };


  // 通用查询条件只保留前两项
  const beforeGetCommonFormInfo = (data: any) => data.slice(0, 2)

  const {
    showAdvancedSearch,
    setShowAdvancedSearch,
    advancedSearchRef,
    advancedSearch,
    advancedSearchForm,
    onSure,
    resetAdvanceSel,
    restoreAdvanceSel,
    advanceFormInfo,
    setCommonFormInfo,
    setFormatFormInfo,
  } = useAdvancedSearch("案例工程指标", onSearch, undefined, beforeGetCommonFormInfo);



  //点击高级搜索按钮的回调
  const openAdvancedSearch = (e: React.MouseEvent) => {
    e.stopPropagation();
    setShowAdvancedSearch(!showAdvancedSearch);
  };


  return <>
    <div>
      <span>文件类型：</span>
      <Select
        placeholder="请选择..."
        style={{ width: 240 }}
        onChange={handleChange}
        allowClear
        options={pageType ?
          [
            { value: 70, label: '招标控制价指标' },
            { value: 52, label: '修正控制价指标' },
            { value: 50, label: '二阶段清标指标' },
          ]
          :
          [
            { value: 70, label: '招标控制价指标' },
            { value: 52, label: '修正控制价指标' },
            { value: 50, label: '二阶段清标指标' },
            { value: 68, label: '评审指标' },
            { value: 66, label: '送内审控制价指标' },
            { value: 41, label: '概算指标' },
            { value: 21, label: '节点结算指标' },
          ]
        }
      />
    </div>
    <div>
      <Search
        value={inputVal}
        enterButton
        onChange={(e) => setInputVal(e.target.value)}
        onSearch={() => onSearch()}
        // onPressEnter={() => onSearch()}
        placeholder="请输入关键字查询"
      /> : <SelectSearch
        searchParams={searchParams}
        setSearchParams={setSearchParams}
        customTypeList={list}
      />
      <Button type="primary" style={{ marginLeft: 10 }} onClick={(e) => openAdvancedSearch(e)}>
        高级筛选
      </Button>
    </div>
    <AdvancedSearch
      open={showAdvancedSearch}
      setOpen={setShowAdvancedSearch}
      ref={advancedSearchRef}
      form={advancedSearchForm}
      querytype="案例工程指标"
      onSure={onSure}
      resetAdvanceSel={resetAdvanceSel}
      restoreAdvanceSel={restoreAdvanceSel}
      advanceFormInfo={advanceFormInfo}
      setCommonFormInfo={setCommonFormInfo}
      setFormatFormInfo={setFormatFormInfo}
      getContainer={() =>
        document.querySelector(".ComparativeEngineeringModal-mainDiv")
      }
      beforeGetCommonFormInfo={beforeGetCommonFormInfo}
    />
  </>
}

//筛选条件
let list = [
  { label: "按项目名称", value: 0 },
  { label: "按合同名称", value: 1 },
  { label: "按子项名称", value: 2 },
]
